package com.propertypoint.presentation.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import com.propertypoint.util.DBUtil;

/**
 * Application Lifecycle Listener implementation class ApplicationContextListener
 *
 */
@WebListener
public class ApplicationContextListener implements ServletContextListener {

    /**
     * Default constructor. 
     */
    public ApplicationContextListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
	public void contextInitialized(ServletContextEvent servletContextEvent) {
		ServletContext ctx = servletContextEvent.getServletContext();

		String url = ctx.getInitParameter("db_url");
		String u = ctx.getInitParameter("db_user");
		String p = ctx.getInitParameter("db_password");
		if (url != null && u != null && p != null) {
			DBUtil.url = url;
			DBUtil.username = u;
			DBUtil.password = p;
		}

	}

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent arg0)  { 
         // TODO Auto-generated method stub
    }
	
}
